package com.example.widget.view

import com.example.base.BaseActivity
import com.example.base.ui.CommonButtonColors
import com.example.base.commonView.CommonText
import com.example.base.commonView.CommonTheme
import com.example.base.commonView.TitleBar
import android.os.Bundle
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material.Button
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.ContextAmbient
import androidx.compose.ui.platform.setContent
import androidx.compose.ui.unit.dp
import com.example.base.ui.white

class StateActivity : BaseActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            showView()
        }
    }

    data class Model(var isOff: Boolean = false)

    @Composable
    fun showView() {
        val context = ContextAmbient.current as BaseActivity
        var counter by remember { mutableStateOf(0) }
        var model by remember { mutableStateOf(Model()) }

        CommonTheme {
            Column(
                modifier = Modifier.fillMaxSize()
            ) {
                TitleBar(title = "状态管理") {
                    context.finish()
                }

                Column(
                    modifier = Modifier.fillMaxSize(),
                    verticalArrangement = Arrangement.Center,
                    horizontalAlignment = Alignment.CenterHorizontally
                ) {
                    Button(
                        onClick = { counter++ },
                        modifier = Modifier.padding(10.dp),
                        colors = CommonButtonColors()
                    ) {
                        CommonText(text = "$counter", color = white)
                    }

                    Button(
                        onClick = { model.isOff = !model.isOff },
                        modifier = Modifier.padding(10.dp),
                        colors = CommonButtonColors()
                    ) {
                        CommonText(text = "${model.isOff}", color = white)
                    }
                }
            }
        }
    }
}